package com.addcn.pushlibrary.jpush;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;
import cn.jpush.android.api.*;
import com.addcn.pushlibrary.BuildConfig;
import com.addcn.pushlibrary.LConfiguration;
import com.addcn.pushlibrary.R;

import java.util.HashSet;
import java.util.Set;

/**
 * author:luwenbo
 * created on date : 2019-05-15
 * content:
 * describe:
 */
public class LJpushManager {

    public static void init(Context context, LConfiguration configuration) {
        if (BuildConfig.DEBUG) {
            JPushInterface.setDebugMode(true);
        } else {
            JPushInterface.setDebugMode(false);
        }
        BasicPushNotificationBuilder builder1 = new BasicPushNotificationBuilder(context);
        builder1.statusBarDrawable = configuration.getSmallIcon();
        JPushInterface.setPushNotificationBuilder(1,builder1);
        JPushInterface.init(context);
    }

    public static void startPush(Context context) {
        JPushInterface.resumePush(context);
    }

    public static void stopPush(Context context) {
        JPushInterface.stopPush(context);
    }


    public static void setAlias(final Context context, String m_id) {
        if (JPushInterface.isPushStopped(context)) {
            return;
        }
        JPushInterface.setAlias(context, m_id, (code, s, set) -> {
            if (code == 0) {
                //成功
            } else {
                Toast.makeText(context, s, Toast.LENGTH_SHORT).show();
            }
        });
    }

    public static void setTag(Context context, String... tags) {
        Set<String> tagList = new HashSet<>();
        if (JPushInterface.isPushStopped(context)) {
            return;
        }
        for (String tag1:tags){
            tagList.add(tag1);
        }
        JPushInterface.setTags(context,tagList.size(),tagList);
       // JPushInterface.setTags();

    }

    public static void deleteTag(Context context, String... tags) {
        Set<String> tagList = new HashSet<>();
        if (JPushInterface.isPushStopped(context)) {
            return;
        }
        for (String tag1:tags){
            tagList.add(tag1);
        }
        JPushInterface.deleteTags(context,tagList.size(),tagList);
    }

}
